package com.example.rabbit.demo.dlx;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import java.io.IOException;

/**
 * @program: rabbit-demo
 * @description:
 * @author: zhaoliang
 * @create: 2019-12-31 11:30
 */
public class MyConsumer extends DefaultConsumer {

    private Channel channel;
    public MyConsumer(Channel channel) {

        super(channel);
        this.channel=channel;
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        System.out.println("==========handleDelivery==========");
        System.out.println("body:"+new String(body));
        if((Integer)properties.getHeaders().get("num") == 1){
            channel.basicNack(envelope.getDeliveryTag(),false,true);
        }else {
            channel.basicAck(envelope.getDeliveryTag(),false);
        }

    }
}
